package com.sky.controller.admin;

import com.sky.constant.RedisConstant;
import com.sky.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

@RestController("adminShopController")
@RequestMapping("/admin/shop")
@Api(tags = "管理端店铺相关")
public class ShopController {

    @Autowired
    private RedisTemplate redisTemplate;

    @ApiOperation("设置店铺状态")
    @PutMapping("/{status}")
    public Result<String> setShopStatus(@PathVariable("status") Integer status){

        redisTemplate.opsForValue().set(RedisConstant.SHOP_STATUS_KEY,status);

        return Result.success();
    }


    @ApiOperation("查看店铺状态")
    @GetMapping("/status")
    public Result<Integer> getShopStatus(){
        Integer status =(Integer) redisTemplate.opsForValue().get(RedisConstant.SHOP_STATUS_KEY);
        if(status==null){
            //考虑到第一次
            status=0;
        }
        return Result.success(status);
    }
}
